package com.itheima.hw.test3;

import java.util.ArrayList;

public class Test {

    public static void main(String[] args) {

        // 准备学生数据
        Student s = new Student("艾大海", "A230602820", "男", 25, "大专以下", "永州职业技术学员");
        Student s2 = new Student("曹少坤", "A230601537", "男", 23, "本科及以上", "");
        Student s3 = new Student("陈橙", "A230600767", "男", 21, "大专 ", "湖南软件职业学员");
        Student s4 = new Student("陈福", "A230601913", "男", 21, "大专", "湖南机电职业技术学员");
        Student s5 = new Student("陈美鹃", "A230600523", "男", 25, "本科及以上", "");
        Student s6 = new Student("陈鑫", "A230601837", "男", 21, "大专以下", "长查民政职业技术学员");
        Student s7 = new Student("陈泳名", "A230601852", "男", 23, "大专", "湖南信息职业技术学员");
        Student s8 = new Student("邓灿宇", "A230601109", "男", 22, "大专", "");
        Student s9 = new Student("邓明", "A230601830", "男", 21, "大专以下", "");
        Student s10 = new Student("付云杰", "A230603250", "男", 22, "大专", "湘西名族职业技术学员");
        Student s11 = new Student("胡振宇", "A230601217", "男", 25, "本科及以上", "湖南涉外经济学员");
        Student s12 = new Student("黄永麒", "A210302017", "男", 23, "本科及以上", "湖南涉外经济学员");
// 创建集合，添加学生数据
        ArrayList<Student> list = new ArrayList<>();
        list.add(s);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);
        list.add(s6);
        list.add(s7);
        list.add(s8);
        list.add(s9);
        list.add(s10);
        list.add(s11);
        list.add(s12);

        // 前端请求数据
        String url = "https://tlias.itcast.cn/tz/classStudentList?name=邓&age=21";

        //1.截取查询条件：name,age
        int nameStart = url.indexOf("=") + 1; //包前
        int nameEnd = url.indexOf("&"); //不包后

        String name = url.substring(nameStart, nameEnd);
        System.out.println(name);

        int ageStart = url.lastIndexOf("=") + 1; //包前
        String ageStr = url.substring(ageStart);

        //2.遍历集合，查询符合条件的学生
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);

            if(student.getName().startsWith( name )   &&   ageStr.equals( student.getAge() + "" )){
                System.out.println(student);  //toString
            }

        }

    }
}
